package com.project.controller;


import com.project.entity.RestPOJO;
import com.project.entity.Role;
import com.project.service.MemberService;
import com.project.service.RoleService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class RoleController {

    @Autowired
    private RoleService roleService;

    @Autowired
    private MemberService memberService;

    @ApiOperation(
            value = "给用户分配角色",
            httpMethod = "GET",
            protocols = "HTTP",
            produces = "application/json",
            response = RestPOJO.class
    )
    //方法的参数说明
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query",name="role_id",value="用户id",required=true),
            @ApiImplicitParam(paramType="query",name="user_id",value="角色id",required=true)
    })
    @RequestMapping("/addUserRole")
    public RestPOJO addUserRole(Integer role_id,Integer user_id){
        RestPOJO restPOJO = new RestPOJO();
        Integer roles = roleService.addUserRole(role_id, user_id);
        Integer integer = memberService.addMember(user_id, 0.0);
        if(roles != null){
            restPOJO.setStatus(1000);
            restPOJO.setMessages("选择成功");
        }else{
            restPOJO.setStatus(1001);
            restPOJO.setMessages("选择失败");
        }
        return restPOJO;
    }

}
